Skip to content

btc(coin): faithful won-block reconstructor closure — reconstruct_won_block (reconstructor slice 5/7) - #839

Merged
frstrtr merged 1 commit into
masterfrom
btc/won-block-reconstruct
Jul 25, 2026
Merged

btc(coin): faithful won-block reconstructor closure — reconstruct_won_block (reconstructor slice 5/7)#839
frstrtr merged 1 commit into
masterfrom
btc/won-block-reconstruct

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Slice 5/7 — the won-block reconstructor closure

Composes the landed sub-slices into the run-loop WonBlockReconstructor the #744 dispatch handler (won_block_dispatch.hpp / make_on_block_found) injects, mirroring p2pool data.py Share.as_block.

  • select_won_block_merkle_link — segwit link-selection SSOT (share_check.hpp:674-692): segwit-activated shares with segwit_data walk segwit_data.txid_merkle_link; legacy (or segwit-active-but-no-segwit_data) shares walk merkle_link. The framer (block_assembly.hpp, slice 4) takes an already-resolved MerkleLink, so the selection lives here in the caller — no new merkle path downstream.
  • reconstruct_won_block — select link + assemble_won_block, taking the captured GBT template (slice 3) as the non-coinbase tx source (NOT the share tx_hash_refs); version-agnostic, coinbase-only on a capture miss.
  • make_reconstruct_closure — the fail-closed run-loop reconstructor: any unknown share / malformed gentx / body-header merkle mismatch is caught, logged loudly, and yields std::nullopt (never throws out of the compute thread, never broadcasts a partial/wrong block; the submitblock RPC fallback still attempts independently).

Seam-first: share-field lookup, gentx regen, and the template-tx snapshot are injected callables → unit-testable with no live ShareTracker / TemplateCapture. The main_btc run-loop binding is slice 7.

Tests — reconstruct_test.cpp, 12 KATs

Link selection (segwit / legacy / no-segwit-data), body round-trip through the live BlockType codec, segwit-link-is-walked, mismatch throw, closure fail-closed on malformed gentx + merkle mismatch, and end-to-end wiring into make_on_block_found (both dual-path arms carry the byte-identical block). Verified locally: btc_share_test 94/94 green; cross-coin smokes green (dgb 34/34, nmc 4/4); diff btc-tree-only (3 files).

Dependency note

Depends on block_assembly.hpp (slice 4, #838), which is not yet on master. Per the base-off-master convention this PR is cut off master (not stacked), so its CI greens once #838 merges; a one-line CMakeLists rebase against #838 may be needed then.

Per-coin isolation: src/impl/btc/ only. p2pool-merged-v36 surface: NONE.

…_block (reconstructor slice 5/7)

Compose the landed sub-slices into the run-loop WonBlockReconstructor the
mirroring p2pool data.py Share.as_block:

  * select_won_block_merkle_link — segwit link-selection SSOT
    (share_check.hpp:674-692): segwit-activated shares with segwit_data walk
    segwit_data.txid_merkle_link, legacy shares walk merkle_link. The framer
    (block_assembly.hpp, slice 4) takes an already-resolved MerkleLink, so the
    selection lives here in the caller — no new merkle path downstream.
  * reconstruct_won_block — select link + assemble_won_block, taking the
    captured GBT template (slice 3) as the non-coinbase tx source (NOT the
    share tx_hash_refs); version-agnostic, coinbase-only on a capture miss.
  * make_reconstruct_closure — the fail-closed run-loop reconstructor: any
    unknown share / malformed gentx / body-header merkle mismatch is caught,
    logged loudly, and yields std::nullopt (never throws out of the compute
    thread, never broadcasts a partial/wrong block; submitblock RPC fallback
    still attempts independently).

Seam-first: share-field lookup, gentx regen, and the template-tx snapshot are
injected callables, so the whole closure is unit-testable with no live
ShareTracker / TemplateCapture. main_btc run-loop binding is slice 7.

reconstruct_test.cpp: 12 KATs — link selection (segwit/legacy/no-segwit-data),
body round-trip through the live BlockType codec, segwit-link-is-walked,
mismatch throw, closure fail-closed on malformed gentx + merkle mismatch, and
end-to-end wiring into make_on_block_found (both dual-path arms carry the
byte-identical block). btc_share_test 94/94 green; diff btc-tree-only.

Per-coin isolation: src/impl/btc/ only. p2pool-merged-v36 surface: NONE.
@frstrtr
frstrtr force-pushed the btc/won-block-reconstruct branch from 4cf5115 to d1ddef1 Compare July 25, 2026 08:54
@frstrtr
frstrtr merged commit 6dc83fd into master Jul 25, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant